package bkone;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class changepingl
 */
@WebServlet("/changepingl")
public class changepingl extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	private static final String DB_USER = "root";
	private static final String DB_PWD = "ZLWL";
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public changepingl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: changepingl").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
		String idreviewerxg = request.getParameter("idreviewerxg");
		String pinglcontentxg = request.getParameter("pinglcontentxg");
		System.out.println("idreviewerxg:" + idreviewerxg);
		System.out.println("pinglcontentxg:" + pinglcontentxg);
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		Connection cont10;
		try {
			cont10 = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
			PreparedStatement prestn10;
			String updatepingl = "update review set review_content = '" + pinglcontentxg + "' where id = ?";
			prestn10 = cont10.prepareStatement(updatepingl);
			prestn10.setString(1, idreviewerxg);
			if(!pinglcontentxg.equals("")){
				prestn10.executeUpdate();
			}
			prestn10.close();
			cont10.close();
			response.sendRedirect("/admin_bloggl.jsp");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
